home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / LevelEditor.as < prev    next >
Text File  |  2007-09-27  |  16KB  |  404 lines

  1. class LevelEditor
  2. {
  3.    static var LETTERS = ["A","B","C","D","E","F","G","H","I","J"];
  4.    static var PANELS = ["Amb_LE_mcGamePanel01","Amb_LE_mcGamePanel02","Amb_LE_mcGamePanel03","Amb_LE_mcGamePanel04","Amb_LE_mcGamePanel05","Amb_LE_mcGamePanel06","Amb_LE_mcGamePanel07","Amb_LE_mcGamePanel08","Amb_LE_mcGamePanel09","Amb_LE_mcGamePanel10"];
  5.    static var SUFFIX_FEATHER = "_F";
  6.    static var SUFFIX_MOONSTONES = "_MS";
  7.    static var PANELS_QTY = 25;
  8.    static var MIN_SECONDS = 180;
  9.    static var MAX_MINUTES = 15;
  10.    static var MIN_MOONSTONES = 5;
  11.    static var MAX_MOONSTONES = 100;
  12.    function LevelEditor(__mcRef, __bEditLevel, __oLevelToEdit, __nNewLevelTargetRow)
  13.    {
  14.       this.mcRef = __mcRef;
  15.       LevelEditor.oCtrl = this;
  16.       this.aPlayObjects = new Array();
  17.       this.aRotateObjects = new Array();
  18.       this.aRotatingObjects = new Array();
  19.       this.bMoving = false;
  20.       if(__bEditLevel)
  21.       {
  22.          this.oLevel = __oLevelToEdit;
  23.       }
  24.       else
  25.       {
  26.          this.oLevel = new BaseLevelData();
  27.          this.oLevel.__set__LevelNumber(__nNewLevelTargetRow);
  28.          this.oLevel.__set__LevelType(BaseLevelData.LEVEL_TYPE_USER);
  29.          this.oLevel.sPanelBg1 = "Amb_LE_mcBgPanel1";
  30.          this.oLevel.aPanelBg2.push("Amb_LE_mcBgPanel2_A");
  31.          this.oLevel.aPanelBg2.push("Amb_LE_mcBgPanel2_B");
  32.          this.oLevel.aPanelBg2.push("Amb_LE_mcBgPanel2_C");
  33.          this.oLevel.__set__RequiredMS(25);
  34.          this.oLevel.__set__TimeAllowed(300000);
  35.          this.oLevel.nFloorHeight = 345;
  36.          this.oLevel.sPanelStart = "Amb_LE_mcGamePanel_Start";
  37.          this.oLevel.sPanelEnd = "Amb_LE_mcGamePanel_End";
  38.          var _loc3_ = 1;
  39.          while(_loc3_ <= LevelEditor.PANELS_QTY)
  40.          {
  41.             var _loc4_ = LevelEditor.PANELS[Library.Utils.MoreMath.getRandomRange(0,LevelEditor.PANELS.length - 1)];
  42.             var _loc2_ = undefined;
  43.             if(Math.random() < 0.5)
  44.             {
  45.                _loc2_ = LevelEditor.SUFFIX_FEATHER;
  46.             }
  47.             else
  48.             {
  49.                _loc2_ = LevelEditor.SUFFIX_MOONSTONES;
  50.             }
  51.             var _loc5_ = _loc4_ + _loc2_;
  52.             this.oLevel.__get__Panels().push(_loc5_);
  53.             _loc3_ = _loc3_ + 1;
  54.          }
  55.          Game.__get__Instance().__get__Status().doAddUserLevel(this.oLevel);
  56.       }
  57.       this.doInit();
  58.       this.doSetUpMachine();
  59.       Main.__get__Instance().doAddListener(this);
  60.    }
  61.    static function get Instance()
  62.    {
  63.       return LevelEditor.oCtrl;
  64.    }
  65.    function doHelpPage(__nPage)
  66.    {
  67.       this.mcRef.mcHelp.gotoAndStop(__nPage);
  68.    }
  69.    function doShowHelp()
  70.    {
  71.       this.mcRef.mcHelp._visible = true;
  72.       this.doHelpPage(1);
  73.    }
  74.    function doHideHelp()
  75.    {
  76.       this.mcRef.mcHelp._visible = false;
  77.    }
  78.    function onMoveStartFor(__mcHit)
  79.    {
  80.       for(var _loc3_ in this.aPlayObjects)
  81.       {
  82.          if(this.aPlayObjects[_loc3_].hitTest(__mcHit))
  83.          {
  84.             this.aPlayObjects[_loc3_].play();
  85.          }
  86.       }
  87.       for(_loc3_ in this.aRotateObjects)
  88.       {
  89.          if(this.aRotateObjects[_loc3_].hitTest(__mcHit))
  90.          {
  91.             this.aRotatingObjects.push(this.aRotateObjects[_loc3_]);
  92.          }
  93.       }
  94.       this.bMoving = true;
  95.    }
  96.    function onMoveStop()
  97.    {
  98.       for(var _loc2_ in this.aPlayObjects)
  99.       {
  100.          this.aPlayObjects[_loc2_].stop();
  101.       }
  102.       this.aRotatingObjects = new Array();
  103.       this.bMoving = false;
  104.    }
  105.    function doAddPlayObject(__mcObj)
  106.    {
  107.       this.aPlayObjects.push(__mcObj);
  108.       __mcObj.stop();
  109.    }
  110.    function doAddRotateObject(__mcObj)
  111.    {
  112.       this.aRotateObjects.push(__mcObj);
  113.    }
  114.    function doEnterFrame()
  115.    {
  116.       if(this.bMoving)
  117.       {
  118.          for(var _loc2_ in this.aRotatingObjects)
  119.          {
  120.             this.aRotatingObjects[_loc2_]._rotation += 10;
  121.          }
  122.       }
  123.    }
  124.    function doBuzzerSound()
  125.    {
  126.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Buzzer.mp3",100,1,true);
  127.    }
  128.    function doSecondsChange(__nChange)
  129.    {
  130.       this.oLevel.TimeAllowed += __nChange * 1000;
  131.       if(this.oLevel.__get__TimeAllowed() > LevelEditor.MAX_MINUTES * 60 * 1000)
  132.       {
  133.          this.oLevel.__set__TimeAllowed(LevelEditor.MAX_MINUTES * 60 * 1000);
  134.          this.doBuzzerSound();
  135.       }
  136.       else if(this.oLevel.__get__TimeAllowed() < LevelEditor.MIN_SECONDS * 1000)
  137.       {
  138.          this.oLevel.__set__TimeAllowed(LevelEditor.MIN_SECONDS * 1000);
  139.          this.doBuzzerSound();
  140.       }
  141.       this.oLevel.__set__Completed(false);
  142.       this.doUpdateTimeNumber();
  143.    }
  144.    function doMinutesChange(__nChange)
  145.    {
  146.       this.oLevel.TimeAllowed += __nChange * 60 * 1000;
  147.       if(this.oLevel.__get__TimeAllowed() > LevelEditor.MAX_MINUTES * 60 * 1000)
  148.       {
  149.          this.oLevel.__set__TimeAllowed(LevelEditor.MAX_MINUTES * 60 * 1000);
  150.          this.doBuzzerSound();
  151.       }
  152.       else if(this.oLevel.__get__TimeAllowed() < LevelEditor.MIN_SECONDS * 1000)
  153.       {
  154.          this.oLevel.__set__TimeAllowed(LevelEditor.MIN_SECONDS * 1000);
  155.          this.doBuzzerSound();
  156.       }
  157.       this.oLevel.__set__Completed(false);
  158.       this.doUpdateTimeNumber();
  159.    }
  160.    function doMoonStonesChange(__nChange)
  161.    {
  162.       this.oLevel.RequiredMS += __nChange;
  163.       if(this.oLevel.__get__RequiredMS() > LevelEditor.MAX_MOONSTONES)
  164.       {
  165.          this.oLevel.__set__RequiredMS(LevelEditor.MAX_MOONSTONES);
  166.          this.doBuzzerSound();
  167.       }
  168.       else if(this.oLevel.__get__RequiredMS() < LevelEditor.MIN_MOONSTONES)
  169.       {
  170.          this.oLevel.__set__RequiredMS(LevelEditor.MIN_MOONSTONES);
  171.          this.doBuzzerSound();
  172.       }
  173.       this.oLevel.__set__Completed(false);
  174.       this.doUpdateMoonStonesNumber();
  175.    }
  176.    function doTestLevel()
  177.    {
  178.       this.oLevel.doSave();
  179.       Game.__get__Instance().doTestLevel(this.oLevel);
  180.    }
  181.    function doExitEditor()
  182.    {
  183.       this.oLevel.doSave();
  184.       Game.__get__Instance().doExitEditor();
  185.    }
  186.    function onLevelNameChange()
  187.    {
  188.       this.oLevel.__set__LevelName(this.mcRef.txtLevelName.text);
  189.    }
  190.    function onToggleFeather()
  191.    {
  192.       if(this.oPanMachine.__get__CurrentState() == "Idle")
  193.       {
  194.          if(this.oPanMachine.__get__CenterMachine().__get__CurrentState() == "Idle")
  195.          {
  196.             this.bBoxUsingFeather = !this.bBoxUsingFeather;
  197.             var _loc3_ = this.getNumberForPanel(this.oLevel.__get__Panels()[this.nCurrentBoxNumber - 1]);
  198.             var _loc2_ = LevelEditor.SUFFIX_MOONSTONES;
  199.             if(this.bBoxUsingFeather)
  200.             {
  201.                _loc2_ = LevelEditor.SUFFIX_FEATHER;
  202.             }
  203.             this.oLevel.__get__Panels()[this.nCurrentBoxNumber - 1] = LevelEditor.PANELS[_loc3_] + _loc2_;
  204.             this.oLevel.__set__Completed(false);
  205.             this.doUpdateFeatherCheck();
  206.          }
  207.       }
  208.    }
  209.    function onScrollPanels(__nMove)
  210.    {
  211.       if(this.oPanMachine.__get__CurrentState() == "Idle")
  212.       {
  213.          if(this.oPanMachine.__get__CenterMachine().__get__CurrentState() == "Idle")
  214.          {
  215.             var _loc3_ = this.getNumberForPanel(this.oLevel.__get__Panels()[this.nCurrentBoxNumber - 1]);
  216.             var _loc2_ = _loc3_ + __nMove;
  217.             if(_loc2_ < 0)
  218.             {
  219.                _loc2_ = LevelEditor.PANELS.length - 1;
  220.             }
  221.             if(_loc2_ > LevelEditor.PANELS.length - 1)
  222.             {
  223.                _loc2_ = 0;
  224.             }
  225.             this.oLevel.__get__Panels()[this.nCurrentBoxNumber - 1] = LevelEditor.PANELS[_loc2_] + this.getCurrentSuffix();
  226.             if(__nMove == 1)
  227.             {
  228.                this.oPanMachine.__get__CenterMachine().doScrollUp();
  229.                this.onMoveStartFor(this.mcRef.mcZone2);
  230.                Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove1.mp3",100,1,true);
  231.             }
  232.             else
  233.             {
  234.                this.oPanMachine.__get__CenterMachine().doScrollDown();
  235.                this.onMoveStartFor(this.mcRef.mcZone1);
  236.                Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove1.mp3",100,1,true);
  237.             }
  238.             this.oLevel.__set__Completed(false);
  239.          }
  240.       }
  241.    }
  242.    function onScrollSide(__nMove)
  243.    {
  244.       if(this.oPanMachine.__get__CurrentState() == "Idle")
  245.       {
  246.          var _loc2_ = this.nCurrentBoxNumber + __nMove;
  247.          if(_loc2_ < 1)
  248.          {
  249.             _loc2_ = LevelEditor.PANELS_QTY;
  250.          }
  251.          if(_loc2_ > LevelEditor.PANELS_QTY)
  252.          {
  253.             _loc2_ = 1;
  254.          }
  255.          this.nCurrentBoxNumber = _loc2_;
  256.          this.doUpdateFeatherCheck();
  257.          if(__nMove == 1)
  258.          {
  259.             this.oPanMachine.doScrollToLeft();
  260.             this.onMoveStartFor(this.mcRef.mcZone4);
  261.             Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove2.mp3",100,1,true);
  262.          }
  263.          else
  264.          {
  265.             this.oPanMachine.doScrollToRight();
  266.             this.onMoveStartFor(this.mcRef.mcZone3);
  267.             Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove2.mp3",100,1,true);
  268.          }
  269.       }
  270.       this.mcRef.txtQtyCur.text = Library.Utils.Tools.getFormatedNumber(this.nCurrentBoxNumber,2);
  271.       this.mcRef.txtQtyAll.text = Library.Utils.Tools.getFormatedNumber(LevelEditor.PANELS_QTY,2);
  272.    }
  273.    function getPanelLinkage(__nPanelNumber)
  274.    {
  275.       return LevelEditor.PANELS[__nPanelNumber];
  276.    }
  277.    function getLinkageFor(__nPanelNumber)
  278.    {
  279.       return this.oLevel.__get__Panels()[__nPanelNumber - 1];
  280.    }
  281.    function getCurrentSuffix()
  282.    {
  283.       var _loc2_ = this.oLevel.__get__Panels()[this.nCurrentBoxNumber - 1];
  284.       var _loc4_ = undefined;
  285.       var _loc3_ = _loc2_.lastIndexOf("_");
  286.       _loc4_ = _loc2_.substring(_loc3_);
  287.       return _loc4_;
  288.    }
  289.    function getNumberForPanel(__sExtendedName)
  290.    {
  291.       var _loc2_ = undefined;
  292.       var _loc1_ = 0;
  293.       while(_loc1_ <= LevelEditor.PANELS.length - 1)
  294.       {
  295.          if(__sExtendedName.indexOf(LevelEditor.PANELS[_loc1_]) != -1)
  296.          {
  297.             _loc2_ = _loc1_;
  298.             _loc1_ = LevelEditor.PANELS.length;
  299.          }
  300.          _loc1_ = _loc1_ + 1;
  301.       }
  302.       return _loc2_;
  303.    }
  304.    function doRefreshVisual()
  305.    {
  306.       this.oPanMachine.doRefreshVisual();
  307.    }
  308.    function doDestroy()
  309.    {
  310.    }
  311.    function get CurrentPanelNumber()
  312.    {
  313.       return this.nCurrentBoxNumber;
  314.    }
  315.    function doSetUpMachine()
  316.    {
  317.       this.oPanMachine = new EditorPanMachine(this.mcRef.mcMachine);
  318.       this.mcRef.btnHelp.onRelease = Library.Utils.Delegate.create(this,this.doShowHelp);
  319.       this.mcRef.btnLeft.onRelease = Library.Utils.Delegate.create(this,this.onScrollSide,-1);
  320.       this.mcRef.btnRight.onRelease = Library.Utils.Delegate.create(this,this.onScrollSide,1);
  321.       this.mcRef.btnUp.onRelease = Library.Utils.Delegate.create(this,this.onScrollPanels,-1);
  322.       this.mcRef.btnDown.onRelease = Library.Utils.Delegate.create(this,this.onScrollPanels,1);
  323.       this.doUpdateFeatherCheck();
  324.       this.mcRef.mcHelp._visible = false;
  325.       this.mcRef.mcHelp.stop();
  326.       this.mcRef.mcHelp.btnExit.onRelease = Library.Utils.Delegate.create(this,this.doHideHelp);
  327.       this.mcRef.mcHelp.btnBlock.useHandCursor = false;
  328.       this.mcRef.mcHelp.btnHelp1.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,4);
  329.       this.mcRef.mcHelp.btnHelp2.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,9);
  330.       this.mcRef.mcHelp.btnHelp3.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,3);
  331.       this.mcRef.mcHelp.btnHelp4.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,8);
  332.       this.mcRef.mcHelp.btnHelp5.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,7);
  333.       this.mcRef.mcHelp.btnHelp6.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,5);
  334.       this.mcRef.mcHelp.btnHelp7.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,2);
  335.       this.mcRef.mcHelp.btnHelp8.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,6);
  336.       this.mcRef.mcHelp.btnHelp1.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  337.       this.mcRef.mcHelp.btnHelp2.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  338.       this.mcRef.mcHelp.btnHelp3.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  339.       this.mcRef.mcHelp.btnHelp4.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  340.       this.mcRef.mcHelp.btnHelp5.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  341.       this.mcRef.mcHelp.btnHelp6.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  342.       this.mcRef.mcHelp.btnHelp7.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  343.       this.mcRef.mcHelp.btnHelp8.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  344.    }
  345.    function doInit()
  346.    {
  347.       this.nCurrentBoxNumber = 1;
  348.       this.mcRef.txtQtyCur.text = Library.Utils.Tools.getFormatedNumber(this.nCurrentBoxNumber,2);
  349.       this.mcRef.txtQtyAll.text = Library.Utils.Tools.getFormatedNumber(LevelEditor.PANELS_QTY,2);
  350.       this.mcRef.btnQuitEditor.onRelease = Library.Utils.Delegate.create(this,this.doExitEditor);
  351.       this.mcRef.btnTest.onRelease = Library.Utils.Delegate.create(this,this.doTestLevel);
  352.       this.mcRef.txtLevelName.text = this.oLevel.LevelName;
  353.       this.mcRef.txtLevelName.restrict = "a-z A-Z 0-9 _";
  354.       this.mcRef.txtLevelName.onChanged = Library.Utils.Delegate.create(this,this.onLevelNameChange);
  355.       this.doUpdateFeatherCheck();
  356.       this.doUpdateMoonStonesNumber();
  357.       this.doUpdateTimeNumber();
  358.    }
  359.    function doUpdateFeatherCheck()
  360.    {
  361.       var _loc2_ = undefined;
  362.       if(this.getCurrentSuffix() == LevelEditor.SUFFIX_FEATHER)
  363.       {
  364.          this.bBoxUsingFeather = true;
  365.          _loc2_ = "On";
  366.       }
  367.       else
  368.       {
  369.          this.bBoxUsingFeather = false;
  370.          _loc2_ = "Off";
  371.       }
  372.       this.mcRef.mcFeatherCheckBox.gotoAndStop(_loc2_);
  373.       this.mcRef.mcFeatherCheckBox.btnToggle.onRelease = Library.Utils.Delegate.create(this,this.onToggleFeather);
  374.       this.doRefreshVisual();
  375.    }
  376.    function doUpdateMoonStonesNumber()
  377.    {
  378.       this.mcRef.mcMoonStones.txtNumber.text = this.oLevel.RequiredMS;
  379.       this.mcRef.mcMoonStones.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doMoonStonesChange,5);
  380.       this.mcRef.mcMoonStones.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doMoonStonesChange,-5);
  381.    }
  382.    function doUpdateTimeNumber()
  383.    {
  384.       var _loc2_ = this.oLevel.__get__TimeAllowed() / 1000 / 60;
  385.       _loc2_ = Math.floor(_loc2_);
  386.       var _loc3_ = undefined;
  387.       if(_loc2_ > 0)
  388.       {
  389.          _loc3_ = this.oLevel.__get__TimeAllowed() / 1000 % (_loc2_ * 60);
  390.       }
  391.       else
  392.       {
  393.          _loc3_ = this.oLevel.__get__TimeAllowed() / 1000;
  394.       }
  395.       _loc3_ = Math.floor(_loc3_);
  396.       this.mcRef.mcMinutes.txtNumber.text = _loc2_;
  397.       this.mcRef.mcSeconds.txtNumber.text = Library.Utils.Tools.getFormatedNumber(_loc3_,2);
  398.       this.mcRef.mcMinutes.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doMinutesChange,1);
  399.       this.mcRef.mcMinutes.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doMinutesChange,-1);
  400.       this.mcRef.mcSeconds.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doSecondsChange,5);
  401.       this.mcRef.mcSeconds.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doSecondsChange,-5);
  402.    }
  403. }
  404.